package com.zrj.marking.entity;

import java.io.Serializable;

/**
 * 响应结果
 *
 * @author zrj
 * @since 2022/10/6
 **/
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 4997257012730493298L;
    /**
     * 状态码
     */
    private static final String SUCCESS_CODE = "200";
    private static final String SUCCESS_MSG = "执行成功";
    private static final String FAIL_CODE = "500";
    private static final String FAIL_MSG = "执行失败";

    /**
     * 提示消息
     */
    private String message;

    /**
     * 状态码
     */
    private String code;

    /**
     * 具体返回的数据
     */
    private T data;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result() {
    }

    public Result(String code, String msg) {
        this.message = msg;
        this.code = code;
    }

    public Result(String code, String message, T data) {
        this.message = message;
        this.code = code;
        this.data = data;
    }

    /**
     * 返回成功Response对象
     */
    public static <T> Result<T> success() {
        return new Result<>( SUCCESS_CODE, SUCCESS_MSG, null );
    }

    public static <T> Result<T> success(T data) {
        return new Result<>( SUCCESS_CODE, SUCCESS_MSG, data );
    }

    public static <T> Result<T> success(String successMessage, T data) {
        return new Result<>( SUCCESS_CODE, successMessage, data );
    }

    public static <T> Result<T> success(String code, String successMessage, T data) {
        return new Result<>( code, successMessage, data );
    }

    /**
     * 返回错误Response对象
     */
    public static <T> Result<T> fail() {
        return new Result<>( FAIL_CODE, FAIL_MSG );
    }

    public static <T> Result<T> fail(String failMsg) {
        return new Result<>( FAIL_CODE, failMsg );
    }

    public static <T> Result<T> fail(String failCode, String failMsg) {
        return new Result<>( failCode, failMsg );
    }

    public static <T> Result<T> fail(String failCode, String failMsg, T data) {
        return new Result<>( failCode, failMsg, data );
    }
}
